/*    */ package blockbuster.components.rate;
/*    */ 
/*    */ import blockbuster.components.BedrockComponentBase;
/*    */ import blockbuster.components.IComponentParticleMorphRender;
/*    */ import blockbuster.components.IComponentParticleRender;
/*    */ import blockbuster.emitter.BedrockEmitter;
/*    */ import blockbuster.emitter.BedrockParticle;
/*    */ import blockbuster.math.Constant;
/*    */ import blockbuster.math.IValue;
/*    */ import blockbuster.math.molang.MolangException;
/*    */ import blockbuster.math.molang.MolangParser;
/*    */ import blockbuster.math.molang.expressions.MolangExpression;
/*    */ import blockbuster.math.molang.expressions.MolangValue;
/*    */ import com.google.gson.JsonElement;
/*    */ import com.google.gson.JsonObject;
/*    */ import net.minecraft.client.renderer.BufferBuilder;
/*    */ 
/*    */ public class BedrockComponentRateSteady extends BedrockComponentRate implements IComponentParticleRender, IComponentParticleMorphRender {
/* 19 */   public static final MolangExpression DEFAULT_PARTICLES = (MolangExpression)new MolangValue(null, (IValue)new Constant(50.0D));
/*    */   
/* 21 */   public MolangExpression spawnRate = MolangParser.ONE;
/*    */ 
/*    */   
/*    */   public BedrockComponentRateSteady() {
/* 25 */     this.particles = DEFAULT_PARTICLES;
/*    */   }
/*    */ 
/*    */   
/*    */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/* 30 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*    */     
/* 32 */     JsonObject element = elem.getAsJsonObject();
/*    */     
/* 34 */     if (element.has("spawn_rate")) this.spawnRate = parser.parseJson(element.get("spawn_rate")); 
/* 35 */     if (element.has("max_particles")) this.particles = parser.parseJson(element.get("max_particles"));
/*    */     
/* 37 */     return super.fromJson((JsonElement)element, parser);
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public JsonElement toJson() {
/* 43 */     JsonObject object = new JsonObject();
/*    */     
/* 45 */     if (!MolangExpression.isOne(this.spawnRate)) object.add("spawn_rate", this.spawnRate.toJson()); 
/* 46 */     if (!MolangExpression.isConstant(this.particles, 50.0D)) object.add("max_particles", this.particles.toJson());
/*    */     
/* 48 */     return (JsonElement)object;
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public void preRender(BedrockEmitter emitter, float partialTicks) {}
/*    */ 
/*    */ 
/*    */   
/*    */   public void render(BedrockEmitter emitter, BedrockParticle particle, BufferBuilder builder, float partialTicks) {}
/*    */ 
/*    */ 
/*    */   
/*    */   public void renderOnScreen(BedrockParticle particle, int x, int y, float scale, float partialTicks) {}
/*    */ 
/*    */ 
/*    */   
/*    */   public void postRender(BedrockEmitter emitter, float partialTicks) {
/* 66 */     if (emitter.playing) {
/*    */       
/* 68 */       double particles = emitter.getAge(partialTicks) * this.spawnRate.get();
/* 69 */       double diff = particles - emitter.spawnedParticles;
/* 70 */       double spawn = Math.round(diff);
/*    */       
/* 72 */       if (spawn > 0.0D) {
/*    */         
/* 74 */         emitter.setEmitterVariables(partialTicks);
/*    */         
/* 76 */         double track = spawn;
/*    */         
/* 78 */         for (int i = 0; i < spawn; i++) {
/*    */           
/* 80 */           if (emitter.particles.size() < this.particles.get()) {
/*    */             
/* 82 */             emitter.spawnParticle();
/*    */           }
/*    */           else {
/*    */             
/* 86 */             track--;
/*    */           } 
/*    */         } 
/*    */         
/* 90 */         emitter.spawnedParticles += track;
/*    */       } 
/*    */     } 
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public int getSortingIndex() {
/* 98 */     return 10;
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\rate\BedrockComponentRateSteady.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */